package com.jiashihui.web.config;

import com.jiashihui.web.filter.InvalidCharacterFilter;
import com.jiashihui.web.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author jiashihui
 * @describe: TODO
 * @date 2019/01/18
 */
@Configuration
public class FilterConfigurer {

    @Bean
    public FilterRegistrationBean testFilterRegistration() {
        // 新建过滤器注册类, 添加我们写好的过滤器
        FilterRegistrationBean registration = new FilterRegistrationBean(new MyFilter());
        // 设置过滤器的URL模式
        registration.addUrlPatterns("/test/*");
        // 初始化参数
        registration.addInitParameter("name", "paramValue");
        // 名称
        registration.setName("myFilter");
        // 设置过滤器顺序
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean authFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean(new InvalidCharacterFilter());
        registration.addUrlPatterns("/redis/*");
        registration.addInitParameter("paramName", "paramValue");
        registration.setName("invalidCharacterFilter");
        registration.setOrder(2);
        return registration;
    }

}
